package classroom;

/**
 * @author yicixingchen
 * @version 1.0
 * Create by 2022/11/1 11:51
 */

public class JosephRing {
    public static void main(String[] args) {
        System.out.println(Joseph(10,2) + 2);
        System.out.println(JosephNonRecursion(10,2) + 2);
    }
    public static int Joseph(int i, int m){
        if(i == 1) return 0;
        return (Joseph(i - 1,m) + m) % i;
    }
    public static int JosephNonRecursion(int n, int m){
        int result = 0;
        for (int j = 2; j <= n; j++) {
            result = (result + m) % j;
        }
        return result;
    }


}
